/*
 * KKLayer.h
 *
 *  Created on: 2013-9-15
 *      Author: wanghua
 */

#ifndef KKLAYER_H_
#define KKLAYER_H_

#include "kaka_common.h"
#include "KKSprite.h"
#include "KKNode.h"
#include "XmlUtils.h"
#include "KKClipableNode.h"

USING_NS_CC;

using namespace std;

class KKLayer: public CCLayer, public KKClipableNode, public CCRGBAProtocol {

protected:
	;CC_PROPERTY(GLubyte, m_nOpacity, Opacity)
	;CC_PROPERTY_PASS_BY_REF(ccColor3B, m_sColor, Color)
	;CC_PROPERTY(bool, m_isOpacityModifyRGB, IsOpacityModifyRGB)
	;CC_SYNTHESIZE(bool, m_limitScroll, LimitScroll)
	;CC_SYNTHESIZE(float,m_hLimitSpace,HLimitSpace)
	;CC_SYNTHESIZE(float,m_vLimitSpace,VLimitSpace)
	;CC_SYNTHESIZE(bool, m_isStopFlingWhenTouch, IsStopFlingWhenTouch)
	;CC_SYNTHESIZE(bool,m_hscroll,HScroll)
	;CC_SYNTHESIZE(bool,m_vscroll,VScroll)
	;CC_SYNTHESIZE(CCSprite*,m_bgImage,BgImage)

protected:

	static const int SMOOTHSCROLL_TAG = 100;

	virtual bool initLayerWithWidthHeight(int width, int height);

	KKLayer();

public:

	virtual ~KKLayer();

	static KKLayer* layerWithWidthHeight(int width, int height);

	static KKLayer* layerWithFile(const char* path);

	virtual bool initWithFile(const char* path);

	KKNODE_FACTORY_METHOD(KKLayer,layerWithXml)
	;

	virtual bool isCascadeOpacityEnabled(void) {
		return isCascadeOpacityEnabled();
	}
	virtual GLubyte getDisplayedOpacity(void) {
		return CCLayerRGBA::create()->getDisplayedOpacity();
	}
	void updateDisplayedOpacity(GLubyte opacity) {
		CCLayerRGBA::create()->updateDisplayedOpacity(opacity);
	}
	void setOpacityModifyRGB(bool bValue) {
	}
	virtual bool isOpacityModifyRGB(void) {
		return false;
	}

	virtual bool isCascadeColorEnabled(void) {
		return CCLayerRGBA::create()->isCascadeColorEnabled();
	}
	const ccColor3B& getDisplayedColor(void) {
		return CCLayerRGBA::create()->getDisplayedColor();
	}
	void updateDisplayedColor(const ccColor3B& color) {
		CCLayerRGBA::create()->updateDisplayedColor(color);
	}
	virtual void setCascadeColorEnabled(bool cascadeColorEnabled) {
		CCLayerRGBA::create()->setCascadeColorEnabled(cascadeColorEnabled);
	}
	virtual void setCascadeOpacityEnabled(bool cascadeOpacityEnabled) {
		CCLayerRGBA::create()->setCascadeOpacityEnabled(cascadeOpacityEnabled);
	}

	virtual bool initCommonInfoWithXml(TiXmlElement* element, KKNode* parent);

	virtual bool initDelayInfoWithXml(TiXmlElement* element);

	virtual void resize(const float& width, const float& height);

	virtual void saveToXml(TiXmlElement* element);

	virtual void onDown(const KKTouch& touch);

	virtual void onScroll(const KKTouch& touch, const CCPoint& dir);

	virtual void onFling(const KKTouch& touch, const CCPoint& velocity);

	virtual void onSmoothScrollEnd();

	virtual void onEnter();

	virtual void onExit();

	virtual CCPoint getLayerLocalPoint(CCPoint point);

	virtual bool layerContains(CCPoint touchPoint);

	virtual CCPoint getLocalTouchPoint(const CCPoint& point);

	virtual bool contains(const CCPoint& touchPoint);

	virtual void setIsVisible(bool isVisible);

	virtual bool getIsVisible() {
		return CCLayer::isVisible();
	}

	virtual void visit();

	virtual void scrollBy(float scrollX, float scrollY);

	virtual void scrollTo(float scrollX, float scrollY);

	virtual void stopSmoothScroll();

	virtual void smoothScrollTo(float scrollX, float scrollY, ccTime duration =
			0.5);

	virtual void smoothScrollBy(float scrollX, float scrollY, ccTime duration =
			0.5);

	virtual float getHScrollMax();

	virtual float getVScrollMax();

	virtual float getHScrollValue();

	virtual float getVScrollValue();

	static KKLayer* node() {
		KKLayer *pRet = new KKLayer();
		if (pRet && pRet->init()) {
			pRet->autorelease();
			return pRet;
		} else {
			delete pRet;
			pRet = 0;
			return 0;
		}
	}
	;
};

KKNODE_PARSER_CLASS(KKLayerParser, KKLayer, layerWithXml);
#endif /* KKLAYER_H_ */
